package com.xm_jd.controller.goods;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.IndexDao;
import com.xm_jd.model.entitys.Pages;
import com.xm_jd.model.entitys.shoop;
import com.xm_jd.utils.BaseServlet;

/**
 * Servlet implementation class PageServlet
 */
@WebServlet("/pagelist")
public class PageServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				request.setCharacterEncoding("utf-8");
				response.setCharacterEncoding("utf-8");
				//��õ�ǰҳ��
				String current = request.getParameter("currentpage");
				Integer currentpage = current==null ? 1:Integer.parseInt(current);
				//��ҳ��С
				int pagesize = 15;
				//�ܼ�¼��
				int total = new IndexDao().getTotalNews();
				//���ݵ�ǰҳ���ҳ��С��ѯ��¼
				List<shoop> list = new IndexDao().getNewsList(currentpage, pagesize);
			
				//��װ
				Pages<shoop> pages = new Pages<>(currentpage,pagesize,total,list);
//				System.out.println(pages.getRows().size());
				//����������
				request.setAttribute("pages", pages);
				//request.getRequestDispatcher("jsps/index.jsp").forward(request, response);
				this.forward("index");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
